# import random
#
#
# # 定义生成8位随机数字账号
# def generate_account_id():
#     return ''.join([str(random.randint(0, 9)) for _ in range(8)])
#
#
# # 定义生成6位随机数字密码
# def generate_password():
#     return ''.join([str(random.randint(0, 9)) for _ in range(6)])
#
#
# # 用户程序字典，用于存储用户信息
# users = {}
#
#
# # 添加用户信息
# def add_user_program():
#     account_id = generate_account_id()  # 系统随机产生8位数字账号
#     password = generate_password()  # 系统随机产生6位数字密码
#     name = input("请输入您的姓名: ")
#     country = input("请输入您的国家: ")
#     province = input("请输入您的省份: ")
#     street = input("请输入您的街道: ")
#     house_number = input("请输入您的门牌号: ")
#     address = f"{country}, {province}, {street}, {house_number}"  # 格式化地址字符串
#     balance = 0  # 初始化存款余额为0
#     bank_name = input("请输入开户行名称: ")
#
#     # 将用户信息添加到字典
#     users[account_id] = {
#         'name': name,
#         'password': password,
#         'address': address,
#         'balance': balance,
#         'bank_name': bank_name
#     }
#
#     print(f"账号: {account_id}, 密码: {password}, 地址: {address}, 存款余额: {balance}, 开户行: {bank_name}")
#
#
# # 主程序入口
# def main():
#     while True:
#         print("\n欢迎使用用户程序")
#         print("1. 添加用户信息")
#         print("2. 退出程序")
#         choice = input("请选择一个选项: ")
#
#         if choice == '1':
#             add_user_program()
#         elif choice == '2':
#             print("感谢使用，再见！")
#             break
#         else:
#             print("无效的选项，请重新输入。")
#
#
# if __name__ == "__main__":
#     main()


import random

# 地址类
class Address:
    def __init__(self, country, province, street, door_number):
        self.country = country
        self.province = province
        self.street = street
        self.door_number = door_number

    def __str__(self):
        return f"{self.country} {self.province} {self.street} {self.door_number}"

# 用户类
class User:
    def __init__(self, name, password, address, balance, bank_name):
        self.account = str(random.randint(10000000, 99999999))  # 随机生成8位账号
        self.name = name
        self.password = password
        self.address = address
        self.balance = balance
        self.bank_name = bank_name

    def __str__(self):
        return f"账号: {self.account}, 姓名: {self.name}, 密码: {self.password}, 地址: {self.address}, 余额: {self.balance}, 开户行: {self.bank_name}"

# 银行类
class Bank:
    def __init__(self, name):
        self.name = name
        self.users = {}  # 用字典存储用户，键为账号，值为User对象

    def add_user(self, user):
        if user.account in self.users:
            return 2  # 用户已存在
        if len(self.users) >= 100:
            return 3  # 用户库已满
        self.users[user.account] = user
        return 1  # 成功

    def deposit(self, account, amount):
        if account not in self.users:
            return False
        self.users[account].balance += amount
        return True

    def withdraw(self, account, password, amount):
        if account not in self.users:
            return 1  # 账号不存在
        if self.users[account].password != password:
            return 2  # 密码不对
        if self.users[account].balance < amount:
            return 3  # 钱不够
        self.users[account].balance -= amount
        return 0  # 正常

    def transfer(self, from_account, to_account, password, amount):
        if from_account not in self.users or to_account not in self.users:
            return 1  # 账号不对
        if self.users[from_account].password != password:
            return 2  # 密码不对
        if self.users[from_account].balance < amount:
            return 3  # 钱不够
        self.users[from_account].balance -= amount
        self.users[to_account].balance += amount
        return 0  # 正常

    def query_account(self, account, password):
        if account not in self.users:
            print("该用户不存在")
            return
        if self.users[account].password != password:
            print("密码错误")
            return
        print(self.users[account])

# 界面程序
def main():
    bank = Bank("中国工商银行昌平支行")
    while True:
        print("\n请选择业务：")
        print("1. 开户")
        print("2. 存钱")
        print("3. 取钱")
        print("4. 转账")
        print("5. 查询账户")
        print("6. 退出")
        choice = input("请输入选项：")

        if choice == "1":
            name = input("请输入姓名：")
            password = int(input("请输入6位数字密码："))
            country = input("请输入国家：")
            province = input("请输入省份：")
            street = input("请输入街道：")
            door_number = input("请输入门牌号：")
            address = Address(country, province, street, door_number)
            balance = int(input("请输入初始存款金额："))
            user = User(name, password, address, balance, bank.name)
            result = bank.add_user(user)
            if result == 1:
                print("开户成功，您的账号为：", user.account)
            elif result == 2:
                print("用户已存在")
            else:
                print("用户库已满")

        elif choice == "2":
            account = input("请输入账号：")
            amount = int(input("请输入存款金额："))
            if bank.deposit(account, amount):
                print("存款成功")
            else:
                print("账号不存在")

        elif choice == "3":
            account = input("请输入账号：")
            password = int(input("请输入密码："))
            amount = int(input("请输入取款金额："))
            result = bank.withdraw(account, password, amount)
            if result == 0:
                print("取款成功")
            elif result == 1:
                print("账号不存在")
            elif result == 2:
                print("密码错误")
            else:
                print("余额不足")

        elif choice == "4":
            from_account = input("请输入转出账号：")
            to_account = input("请输入转入账号：")
            password = int(input("请输入转出账号密码："))
            amount = int(input("请输入转账金额："))
            result = bank.transfer(from_account, to_account, password, amount)
            if result == 0:
                print("转账成功")
            elif result == 1:
                print("账号不存在")
            elif result == 2:
                print("密码错误")
            else:
                print("余额不足")

        elif choice == "5":
            account = input("请输入账号：")
            password = int(input("请输入密码："))
            bank.query_account(account, password)

        elif choice == "6":
            print("退出系统")
            break

        else:
            print("无效选项，请重新输入")

if __name__ == "__main__":
    main()